package com.wang.controller;


import com.wang.enums.CouponCategoryEnum;
import com.wang.request.NewUserCouponRequest;
import com.wang.service.CouponService;
import com.wang.util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 落日孤城
 * @since 2025-05-10
 */
@Api("优惠券模块")
@RestController
@RequestMapping("/api/coupon/v1")
public class CouponController {
    @Autowired
    private CouponService couponService;

    @ApiOperation("优惠券分页查询")
    @GetMapping("/page_coupon")
    public JsonData pageCouponList(
            @ApiParam("当前页")
            @RequestParam(value = "page",defaultValue = "1")
            Integer page,

            @ApiParam("每页显示多少条")
            @RequestParam(value = "size",defaultValue = "10")
            Integer size
    ){
        Map<String, Object> stringObjectMap = couponService.pageCouponActivity(page, size);
        return JsonData.buildSuccess(stringObjectMap);
    }


    @ApiOperation("领取优惠券")
    @PostMapping("/add/promotion/{coupon_id}")
    public JsonData addPromotionCoupon(
            @ApiParam(value = "优惠券id",  required = true)
            @PathVariable("coupon_id")
            Long couponId){
        JsonData jsonData = couponService.addCoupon(couponId, CouponCategoryEnum.PROMOTION);
        return jsonData;
    }

    @ApiOperation("RPC-新人注册接口")
    @PostMapping("/new_user_coupon")
    public JsonData newUserCoupon(
            @ApiParam("用户对象")
            @RequestBody NewUserCouponRequest newUserCouponRequest
    ){
        JsonData jsonData = couponService.initNewUserCoupon(newUserCouponRequest);
        return jsonData;
    }
}

